/*
 * @Author: your name
 * @Date: 2020-02-17 10:19:08
 * @LastEditTime: 2020-08-22 11:27:56
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \boot_vue\src\store\index.js
 */
import Vue from 'vue'
import Vuex from 'vuex'
import cloneDeep from 'lodash/cloneDeep'
import user from './modules/user'
import dict from './modules/dict'
import EquTypeList from './modules/EquTypeList'
import fullScreen from './modules/fullScreen'

Vue.use(Vuex)

export default new Vuex.Store({
  namespaced: true,
  state: {
    questionTemplate: '',
    questionTemplateName: '',
    rulesStatus: 1,
    // 填报工作流
    fillingFlow: 1,
    // 工作流状态
    workflowStatus: 1,
    // 是否显示大屏监控
    isConsole: false,
    // 是否启动图表刷新
    refresheChar: false,
    // 需要刷新的图表列表
    refresheCharList: {},
    // 是否显示大屏
    isPlatform: false,
    initialization: {},
    // 权限列表
    permissions: [],
    // 导航条, 布局风格, defalut(白色) / colorful(鲜艳)
    navbarLayoutType: 'colorful',
    // 侧边栏, 布局皮肤, default(白色) / dark(黑色)
    sidebarLayoutSkin: 'dark',
    // 侧边栏, 折叠状态
    sidebarFold: false,
    // 侧边栏, 菜单
    sidebarMenuList: [],
    sidebarMenuActiveName: '',
    // 头部菜单栏的选中项
    activeHeaderMenu: '',
    // 内容, 是否需要刷新
    contentIsNeedRefresh: false,
    // 内容, 标签页(默认添加首页)
    contentTabs: [
      {
        ...window.SITE_CONFIG['contentTabDefault'],
        'name': 'home',
        'title': 'home'
      }
    ],
    contentTabsActiveName: 'home'
  },
  modules: {
    user,
    dict,
    EquTypeList,
    fullScreen
  },
  mutations: {
    // 设置图表刷新
    setRefresheChar (state, data) {
      state.refresheChar = data
      if (!data) {
        state.refresheCharList = {}
      }
    },
    // 添加需要刷新的图表
    setRefresheCharList (state, data) {
      Vue.set(state.refresheCharList, data.name, data.vm)
    },
    // 重置vuex本地储存状态
    resetStore (state) {
      Object.keys(state).forEach((key) => {
        state[key] = cloneDeep(window.SITE_CONFIG['storeState'][key])
      })
    },
    // 设置是否显示监控台
    setConsole (state, data) {
      state.isConsole = data
    },
    setContentIsNeedRefresh (state, data) {
      state.contentIsNeedRefresh = data
    },
    // 设置工作流状态
    setWorkflowStatus (state, data) {
      state.workflowStatus = data
    },
    // 设置填报工作流状态
    setFillingflowStatus (state, data) {
      state.fillingFlow = data
    },
    setRulesStatus (state, data) {
      state.rulesStatus = data
    },
    setQuestionTemplate (state, data) {
      state.questionTemplate = data.id
      state.questionTemplateName = data.name
    },
    // 保存dataForm的初始值
    setInitialization (state, data) {
      state.initialization = Object.assign({}, {}, data)
    },
    setSidebarMenuList (state, data) {
      state.sidebarMenuList.splice(0, state.sidebarMenuList.length, ...data)
    },
    setActiveHeaderMenu (state, data) {
      state.activeHeaderMenu = data
    }
  }
})
